package org.wutopia.labcloud.domain.uaa.mq.consumer;


import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;
import org.wutopia.labcloud.domain.uaa.service.email.IEmailService;

@Slf4j
@Service
@RocketMQMessageListener(
        topic = "UAA-TOPIC",
        selectorExpression = "email-code",  // 消费多个Tag
        consumerGroup = "uaa-consumer-group"
)
@AllArgsConstructor
public class UserGetEmailCodeConsumer implements RocketMQListener<String> {

    private IEmailService iEmailService;

    @Override
    public void onMessage(String code) {

        if(code == null) {
            return;
        }

        String[] split = code.split(":");
        String email = split[0];
        String ecode = split[1];

        try {
            iEmailService.sendText(email, "email code", "验证码：" + ecode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
